package fr.umlv.m2.jee.pmlv.persistence.subject;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 * Represents a comment posted by a user for a subject.
 * @author jenseric
 *
 */
@SuppressWarnings("serial")
@Entity
@Table(name ="Comment")
public class Comment implements Serializable{


	/**
	 * Id of the comment
	 */
	@Id
	@GeneratedValue
	@Column(name ="comment_id")
	private long id;

	/**
	 * Text of the comment.
	 */
	@Column(name = "comment_text")
	private String text;


	/**
	 * The date when the comment is posted.
	 */
	@Column(name = "comment_postedAt")
	@Temporal(TemporalType.DATE)
	private Date postedAt;

	/**
	 * The {@link Subject} concerned by the Comment.
	 */
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name="subject_id", nullable=false)
	private Subject subject;

	/**
	 * Sets the id of the comment.
	 * @param id the integer that is to be the id of the Comment.
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * Returns the id of the comment.
	 * @return the id of the comment.
	 */
	public long getId() {
		return id;
	}


	/**
	 * Sets the text of the comment.
	 * @param text String that is to be the text of the Comment.
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * Return the text which represents the comment.
	 * @return the text which repreents the comment.
	 */
	public String getText() {
		return text;
	}

	/**
	 * Sets the date when the comment was posted.
	 * @param post the date that is be the date when the comment was posted.
	 */
	public void setPostedAt(Date postedAt) {
		this.postedAt = postedAt;
	}

	/**
	 * Returns the date when the comment was posted.
	 * @return the time when the comment was posted.
	 */
	public Date getPostedAt() {
		return postedAt;
	}

	/**
	 * Sets the subject which is commented.
	 * @param subject the subject that is to be commented.
	 */
	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	/**
	 * Returns the subject whish is commented.
	 * @return the {@link Subject} which is commented.
	 */
	public Subject getSubject() {
		return subject;
	}


}
